package com.example.gener.rongyundemo.singleChat;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;

import com.example.gener.rongyundemo.R;
import com.jk.myimkit.imkit.fragment.ConversationFragment;

import io.rong.imlib.model.Conversation;

public class SingleChatActivity extends AppCompatActivity {
    private ConversationFragment chatRoomFragment;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_siginle_chat);

        initSingleChatFragment();
    }
    public static void start(Context context) {
        context.startActivity(new Intent(context, SingleChatActivity.class));
    }
    private void initSingleChatFragment() {
        chatRoomFragment = new ConversationFragment();
        Uri uri = Uri.parse("rong://" + getApplicationInfo().packageName).buildUpon()
                .appendPath("rc_conversation").appendPath(Conversation.ConversationType.PRIVATE.getName().toLowerCase())
                .appendQueryParameter("targetId", "jiangdashuai").build();
        chatRoomFragment.setUri(uri);

        FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
//        fragmentTransaction.setCustomAnimations(R.anim.fragment_slide_in_from_left,R.anim.fragment_slide_out_from_left);
        if (!chatRoomFragment.isAdded()) {
            fragmentTransaction.add(R.id.rl_single_chat_container, chatRoomFragment, "SingleChatFragment").commit();
        } else {
            fragmentTransaction.show(chatRoomFragment).commit();
        }

    }


}
